
#include "boom_hard.h"

Boom_hard::Boom_hard():Qpixmapitem()
{

}


Boom_hard::Boom_hard(const QString filename,QGraphicsScene *scene,qreal angle):Qpixmapitem(filename,scene)
{
    this->scence=scene;
    qreal dx,dy;
    qreal rad=angle*3.14/180;
    dx=250*cos(rad);
    dy=250*sin(rad);
    this->setPos(scene->width()/2+dx,scene->height()-dy);
    this->setRotation(90-angle);
}


void Boom_hard::advance(int phase)
{
    if(mapToScene(0,0).x()<=0||mapToScene(0,0).x()>=2000||mapToScene(0,0).y()<=0)//子弹跳出屏幕
        delete this;


    else//子弹移动
        this->setPos(mapToScene(0,-50));
}


void Boom_hard::paint(QPainter*painter,const QStyleOptionGraphicsItem* option,QWidget* widget)
{
    painter->drawPixmap(-pixmap.width()/2,-pixmap.height(),pixmap);
    if(this->collidingItems().count()>0)
        docolliding();
}


void Boom_hard::docolliding()
{

    Net_hard*net=new Net_hard("img/net_hard",this->scence);//产生一个网
    net->setPos(mapToScene(0,0));
    delete this;//删掉炮弹
}

